using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using Facebook.Controls.Properties;
using Facebook.Entity;
using Facebook.Utility;

namespace Facebook.Controls
{
    [ToolboxItem(true), ToolboxBitmap(typeof(BaseControl))]
    public partial class Profile : BaseControl
    {
        private User _user = null;
        private string _status = string.Empty;

        [Category("Facebook")]
        [Description("")]
        public User User
        {
            get { return _user; }
            set
            {
                _user = value;
                OnLoad();
            }
        }

        public string Status
        {
            get { return _status; }
            set
            {
                _status = value;
                OnLoad();
            }
        }

        public Profile()
        {
            InitializeComponent();
        }

        private void OnLoad()
        {
            if (!IsDesignTime() && _user != null)
            {
                LoadControls();
            }
        }

        private void LoadControls()
        {
            LoadBasicInfoPanel(_user);            
            LoadPicture(_user);
        }

        private void LoadPicture(User user)
        {
            if (user.PictureUrl != null)
            {
                pbProfilePicture.ImageLocation = user.PictureUrl.ToString();
            }
            else
            {
                pbProfilePicture.Image = user.Picture;
            }
        }

                  

        private void LoadBasicInfoPanel(User user)
        {
            if (_status == string.Empty)
            {
                if (user.Status.Message == string.Empty)
                {
                    lblStatus.Text = "What are you doing right now?";
                }
                else
                {
                    lblStatus.Text = user.Status.Message;
                }
            }
            else
            {
                lblStatus.Text = _status;
            }

            lblName.Text = user.Name;            
            lblSex.Text = EnumHelper.GetEnumDescription(user.Sex);
            lblInterestedIn.Text = EnumHelper.GetEnumCollectionDescription(user.InterestedInGenders);
            lblRelationshipStatus.Text = EnumHelper.GetEnumDescription(user.RelationshipStatus);
            lblLookingFor.Text = EnumHelper.GetEnumCollectionDescription(user.InterstedInRelationshipTypes);
            if (user.Birthday.HasValue)
            {
                lblBirthday.Text = user.Birthday.GetValueOrDefault().ToString("yyyy/MM/dd");
            }
            else
            {
                lblBirthday.Text = string.Empty;
            }
            lblHometown.Text = user.HometownLocation.ToString();
            lblPoliticalViews.Text = EnumHelper.GetEnumDescription(user.PoliticalView);
            lblReligiousViews.Text = user.Religion;

        }        

        private static Label CreatePromptLabel(string text)
        {
            Label label = new Label();
            label.Text = text + ":";
            label.Font = new Font("Tahoma", 8.25f);
            label.ForeColor = Color.Gray;
            label.Dock = DockStyle.Top;
            label.Margin = new Padding(3, 3, 3, 0);
            label.AutoSize = true;

            return label;
        }

        private static Label CreateValueLabel(string text)
        {
            Label label = new Label();
            label.Text = text;
            label.Font = new Font("Tahoma", 8.25f);
            label.ForeColor = Color.FromArgb(96, 120, 205);
            label.Dock = DockStyle.Top;
            label.Margin = new Padding(3, 3, 3, 0);
            label.AutoSize = true;

            return label;
        }


        #region Event Handlers

        private void Profile_Load(object sender, EventArgs e)
        {
            OnLoad();
        }

        private void lblStatus_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            
        }

        #endregion Event Handlers





    }
}
